package com.springboot.controller;

import javax.validation.Valid;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.springboot.entity.News;
import com.springboot.service.NewsService;

@RestController
public class NewsControl
{
    private  static Logger logger = LoggerFactory.getLogger(NewsControl.class); 
    @Autowired
    private NewsService newsService;

    @RequestMapping(value = "hello")
    public String getName()
    {
        return "nihao";
    }

    @RequestMapping(value = "save")
    public void save(@Valid News news,BindingResult bindingResult)
    {
        if(bindingResult.hasErrors())
        {
            System.out.println(bindingResult.getFieldError().getDefaultMessage());
            return;
        }
        newsService.save(news);
    }

}
